const AutoImport = require('unplugin-auto-import/webpack')
const Components = require('unplugin-vue-components/webpack')
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers')
const CompressionPlugin = require('compression-webpack-plugin')

module.exports = {
  publicPath: '/',
  lintOnSave: false,
  productionSourceMap: process.env.NODE_ENV === 'development',
  devServer: {
    host: '0.0.0.0',
    open: true,
    port: 8080,
    https: false,
    proxy: {
      '/api': {
        target: 'http://localhost:6060/api',
        ws: true,
        changOrigin: true,
        pathRewrite: {
          '^/api': ''
        }
      },
      '/upload': {
        target: 'https://image.zdxblog.cn/upload',
        ws: true,
        changOrigin: true,
        pathRewrite: {
          '^/upload': ''
        }
      }
    }
  },
  configureWebpack: {
    devtool: 'source-map',
    plugins: [
      AutoImport({
        resolvers: [ElementPlusResolver({ importStyle: false })]
      }),
      Components({
        resolvers: [ElementPlusResolver({ importStyle: false })]
      }),
      new CompressionPlugin({
        test: /\.js$|\.html$|\.css$/, // 匹配需要压缩的文件类型
        threshold: 10240, // 文件大小大于10kb时才会被压缩
        deleteOriginalAssets: false // 是否删除原文件
      })
    ]
  }
}
